<template>
  <div style="width: 100%;position: static" class="cjyMode" ref="cjyMode">
    <transition name="mask">
      <div style="width: 100%;height: 100%;top: 0;left: 0;position: absolute;background: rgba(0,0,0,.3);" v-if="isShow"
           @click="isBagCart ? '' : isShow=false">
      </div>
    </transition>
    <transition name="content">
      <div v-show="isShow" id="service_description" class="purchase_service" style="display: block;min-height: 20vh;z-index: 2"
           :style="{height:height,background:backgroundColor}">
        <slot>

        </slot>
        <div class="cjy-button-box" @click="close">
          <div class="cjy-button">{{buttonText}}</div>
        </div>
      </div>
    </transition>
  </div>

</template>

<script>
  // import Hello from './components/Hello'

  export default {
    data() {
      return {
        isShow: false,
        clickOver: true,
      }
    },
    components: {},
    props: {
      height: {
        type: String,
        default: '20rem'
      },
      buttonText: {
        type: String,
        default: '关闭'
      },
      backgroundColor: {
        type: String,
        default: 'white'
      },
      isBagCart: {
        type: Boolean,
        default: false
      }
    },
    methods: {
      showModle() {
        this.isShow = true;
        this.refresh()
        this.clickOver = false
        this.setTimeOut && clearTimeout(this.setTimeOut)
        this.setTimeOut = setTimeout(() => {
          this.clickOver = true
        }, 500)
      },
      refresh() {

      },
      close() {
        if (!this.clickOver) {
          return
        }
        this.isShow = false;
        this.$emit("isClossing");
      }
    },
    mounted() {
      this.$nextTick(() => {
        var cjyMode = this.$refs.cjyMode
        var container = document.querySelector('.container-box')
        container.appendChild(cjyMode)

      })
    },
    beforeDestroy() {
      var container = document.querySelector('.container-box')
      console.log(container,'23423423')
      var cjyMode = this.$refs.cjyMode
      container.removeChild(cjyMode)
    }
  }
</script>

<style scoped>
  .mask-enter-active, .mask-leave-to-active, .content-enter-active, .content-leave-to-active {
    transition: 0.3s;
  }

  .mask-enter, .mask-leave-to {
    opacity: 0.3
  }

  .content-enter, .content-leave-to {
    transform: translatey(100%)
  }

  .cjy-button-box {
    height: 2.5rem;
    background: rgba(255, 255, 255, 0.9);
    overflow: hidden;
    position: absolute;
    /* padding: 0.5rem 0.75rem;*/
    width: 100%;
    left: 0;
    bottom: 0px;
    display: table;
    border-top: 1px solid #eaeaea;
    z-index: 1;
  }

  .cjy-button {
    font-size: 1rem;
    height: 2.5rem;
    line-height: 2.5rem;
    background-color: #EF5423;
    color: #ffffff;
    border-radius: 0.2rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    vertical-align: middle;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    border-radius: 0px;
  }

</style>
